program ChromeReleaseRevision;

include <core.vhs>
include <netutil.vhs>
include <shell.vhs>
include "chrome.vhs"

import core::*;
import core::Pattern::*;
import core::Logging::*;
import shell::*;
import netutil::*;

function main(input='releases.txt') {
	var outfile = new CsvFile('ver2rev2.csv');
	ReleaseEntry(input=new SequenceStream(input, 4096), maxOccur=1, outfunc = function(data) {
		outfile.writeCsvLine([data.version, data.revision]);
	});
	outfile.close();
}

pattern<DataPart> ReleaseEntry($dataPattern=@"win,stable,([^,]*),[^\n]*\n", $minOccur=0, $maxOccur=INFINITY, $outfunc) {
	var ver = this[1] + '';
	var revPattern = pattern<DataPart>($dataPattern=@'\d+') this[0];
	var f = download('http://omahaproxy.appspot.com/revision?version=' + ver);
	var rev = revPattern(input = new SequenceStream(f, 4096));
	outfunc?(struct { version = ver, revision=rev } );
}
